package com.manshutingyu.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import com.manshutingyu.system.domain.SysMenu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

/**
 * @Author：yinyuxia
 * @Date：2025/3/29 17:44
 */
public interface SysMenuMapper extends BaseMapper<SysMenu> {

    @Select("SELECT   DISTINCT p.permission  FROM sys_user_role ar  LEFT JOIN sys_role r ON ar.role_id = r.id  LEFT JOIN sys_role_menu rp ON r.id = rp.role_id   LEFT JOIN sys_menu p ON rp.menu_id = p.id  WHERE  ar.user_id = #{userId}   AND p.permission IS NOT NULL     AND p.del_flag = 1    AND r.del_flag = 1")
    Set<String> getMenuPermission(@Param("userId") Long useId);


    /**
     * 根据用户ID查询菜单
     *
     * @param userId
     * @return
     */
    @Select("SELECT DISTINCT  m.id, m.parent_id, m.name, uri, m.type, m.icon, m.sort, m.path, m.cache_flag,  m.params  FROM  sys_menu m  LEFT JOIN sys_role_menu rm ON m.id = rm.menu_id   LEFT JOIN sys_user_role ur ON rm.role_id = ur.role_id  WHERE  ur.user_id = #{userId}   AND m.type IN ( '0', '1' ,'3')  AND m.del_flag = 0  ORDER BY    m.parent_id,   m.sort")
    List<SysMenu> getRoutersByUserId(@Param("userId") Long userId);

    /**
     * 获取用户所有权限
     * @param userId
     * @return
     */
    @Select("SELECT     p.*   FROM  sys_user_role ar   LEFT JOIN sys_role r ON ar.role_id = r.id   LEFT JOIN sys_role_menu rp ON r.id = rp.role_id   LEFT JOIN sys_menu p ON rp.menu_id = p.id    WHERE  ar.user_id = #{userId}   ORDER BY p.sort ")
    List<SysMenu> getPermissionList(@Param("userId") Long userId);
}


